<?php
class Control_Sidebar extends QUI_Control_Abstract {
    function render() {

        //        dump($this->_attrs->roles);
        $user = Helper_RBAC::get('user');
        if(!$user->id()) return '';
        //        dump($user);
        //        dump($user->roles);
        //        dump(FUNC::setArrayByField(array('role_id'), $user->roles->toArray()));
        //        $this->_view['username'] = $this->_attrs ->username;
        //        $this->_view['group'] = Role::droplist(array('name'=>'role_id[]'), FUNC::setArrayByField(array('role_id'), $user->roles->toArray()), true);
        //        dump(Role::droplist(array('name'=>'role_id[]'), FUNC::setArrayByField(array('role_id'), $user->roles->toArray()), true));
        //        $this->_view['attrs'] = $this->_attrs;
        //        dump($this->_view['group']);

        $count_something = Helper_Cache::read(Helper_Common::iniFront('counter_cache'));
        $count_something = null;

        if(!$count_something) {

            $condi[] = new QDB_Cond(
'[to_users.user_id] = ? AND [to_users.receiver_del] = 0', $user->user_id
            );
            //            $condi[] = new QDB_Cond(
            //            'hasremove = ?', 0
            //            );

            $blongs_myself[] = new QDB_Cond(
            'user_id = ?',  $user->user_id
            );

            //            $blongs_myself[] = new QDB_Cond(
            //            'hasremove = ?', 0
            //            );

            $count_something['message_count'] = Message::find($condi)->all()->getCount();

            $count_something['has_view_message_count'] = Message::find('[view_users.user_id]=?', $user->user_id)->all()->getCount();

//echo $count_something['has_view_message_count'];
            $in_notice_cols = FUNC::getChildren(Column::getFormCache(null, Helper_Common::iniFront('notice_column_id')), $childrens, array('col_id'), false);    //查找孩子
            $in_notice_cols[] = Helper_Common::iniFront('notice_column_id');
                                                          

            $childrens = null;  //必须设置

            $in_share_cols = FUNC::getChildren(Column::getFormCache(null, Helper_Common::iniFront('share_column_id')), $childrens, array('col_id'), false);    //查找孩子
            $in_share_cols[] = Helper_Common::iniFront('share_column_id');

            //            dump($in_share_cols);

            $count_something['article_notice_count'] = Article::find($blongs_myself)->where('col_id in ('.FUNC::getIdset($in_notice_cols, null, false).')')->getCount('art_id');

            $count_something['article_share_count'] = Article::find($blongs_myself)->where('col_id in ('.FUNC::getIdset($in_share_cols, null, false).')')->getCount('art_id');

            Helper_Cache::write(Helper_Common::iniFront('counter_cache'), $count_something);
/*

                   *
                         */
        }
        //        echo $article_notice_count;
        //        echo $message_count;
        //                dump($count_something);

        $this->_view['article_notice_count'] = $count_something['article_notice_count'];
        $this->_view['article_share_count'] = $count_something['article_share_count'];
        $this->_view['new_message_count'] = $count_something['message_count'] - $count_something['has_view_message_count'];
        $this->_view['message_count'] = $count_something['message_count'];
        $this->_view['user'] = $user;
        return $this->_fetchView('view:' .Helper_Common::currentStyle(). '/_control/sidebar');
    }
}
?>